<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>文档</title>
  <link href="../css/semantic/semantic.min.css" rel="stylesheet">
  <link href="../css/markdown.css" rel="stylesheet">
  <link href="../css/wtxynavigation.css" rel="stylesheet">
  <script src="../js/jquery.min.js"></script>
  <script type="text/javascript" src="../js/include.js"></script>
  <style>
    body{padding-top:0;background:#f7f7f7}
    body>.ui.container{width:100%;padding:0}
    #project-title{background:#6e6e6e;width:100%;line-height:3.572rem;color:#fff;font-size:1.2rem}
    #project-title .title-wrap{font-weight:700;padding:0 12px;width:100%;max-width:1366px!important;min-width:900px;margin:0 auto}
    #project-title .left,#project-title right{display:inline-block}
    #project-title .right{float:right}
    #project-title .right .wiki-actions .menu{left:auto;right:0;margin-top:.4em!important}
    #wiki-preview-container{width:100%;max-width:1366px!important;min-width:900px;padding:0;border:1px solid #e3e9ed;border-top:0}
    #wiki-preview>.ui.segment{margin-top:0;padding:1rem;padding-left:0;border:0}
    .hover-places{display:inline-block}
    #page-detail{width:60%;margin:0 auto}
    #page-detail .title{font-weight:700;font-size:24px;padding:12px 0;border-bottom:1px solid #ccc}
    #page-detail .content{margin-top:15px}
    .content p{word-wrap:break-word}
    #wiki-parent,#wiki-title,#wikis{display:none}
    .ui.grid{padding:0!important}
    #ex-all{cursor:pointer;color:#537c8d}
  </style>
</head>
<body>
  <div class="ui container">
    <div id="project-title">
      <div class="title-wrap">
        <div class="left">
          <i class="icon eye"></i>
          文档预览:
          mianmSDK
        </div>
        <div class="right">
          Export by Gitee
        </div>
      </div>
    </div>

    <div class="ui container" id="wiki-preview-container">
      <div id="wiki-preview">
        <div class="ui segment">
          <div id="page-detail" class="markdown-body">
            <div class='title'>24.runtime类对象和元类对象</div><div class='content'><h1>
<a id="24runtime类对象和元类对象介绍" class="anchor" href="#24runtime%E7%B1%BB%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%85%83%E7%B1%BB%E5%AF%B9%E8%B1%A1%E4%BB%8B%E7%BB%8D"></a>24.runtime类对象和元类对象介绍</h1>
<p><strong>关键词</strong>: <code>对象</code>, <code>类对象</code>, <code>元类对象</code>,<code>isa</code>,<code>mate</code></p>
<h2>
<a id="241-对象-类对象-元类对象" class="anchor" href="#241-%E5%AF%B9%E8%B1%A1-%E7%B1%BB%E5%AF%B9%E8%B1%A1-%E5%85%83%E7%B1%BB%E5%AF%B9%E8%B1%A1"></a>24.1 对象, 类对象, 元类对象</h2>
<ul>
<li>
<strong>类对象</strong>存储<strong>实例方法</strong>列表等信息</li>
<li>
<strong>元类对象</strong>存储<strong>类方法</strong>列表等信息</li>
</ul>
<p><img src="../images/runtimeOCM01.png" alt="runtimeOCM01"></p>
<ol>
<li>
<strong>Root class(class)</strong>: 对应的就是<strong>OC</strong>里面的<code>NSObject</code>, 它没有父类,父类指针指向nil</li>
<li>
<strong>instance of</strong>: 代表的就是<strong>实例对象</strong>, 它的<strong>isa</strong>指针指向它的<strong>类对象</strong>
</li>
<li>
<strong>mate</strong>: 上图最右边的话呢就是<strong>元类对象</strong>, 其中最上面的是<strong>根元类对象</strong>
</li>
<li>
<strong>类对象</strong>的<strong>isa</strong>指针指向其<strong>元类对象</strong>
</li>
<li>任何<strong>元类对象</strong>的<strong>isa</strong>指针全部指向<strong>根元类对象</strong>,包括<strong>根元类对象</strong>自己的<strong>isa</strong>指针也是.</li>
<li>
<strong>元类对象</strong>和<strong>元类对象</strong>他们都是<code>objc_class</code>结构</li>
<li>然后<code>objc_class</code>是继承自<code>objc_object</code>的所以他们都有<strong>isa</strong>指针</li>
<li>
<strong>根元类对象</strong>的<strong>superClass</strong>指针指向<strong>根类对象</strong>
<ul>
<li>
<ol>
<li>这样的指向就决定了一个性质, 比如说我们调用的一个<strong>类方法</strong> 肯定要在<strong>元类对象</strong>中查找,然后沿着<strong>superClass</strong>指针逐级查找, 找到<strong>根元类对象</strong>还找不到, 然后就去<strong>根类对象</strong>中查找同名的实例方法.</li>
</ol>
</li>
</ul>
</li>
</ol>
<ul>
<li>
<strong>实例</strong>通过<strong>isa</strong>指针可以找到它的<strong>类对象</strong>,进而可以访问<strong>实例方法</strong>
</li>
<li>
<strong>类对象</strong><em>通过</em><em>isa</em><em>指针可以找到它的</em><em>元类对象</em>*, 然后可以访问<strong>类方法</strong>
</li>
</ul></div>
          </div>
        </div>
      </div>
      </div>
  </div>
</body>
</html>